package edu.zut.cs.software.perfect.grade.web.spring.controller;

import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;

import edu.zut.cs.software.perfect.base.web.spring.controller.GenericController;
import edu.zut.cs.software.perfect.grade.domain.CourseGrade;
import edu.zut.cs.software.perfect.grade.service.CourseGradeManager;


/**
 * @ClassName CourseGradeController
 * @Description TODO
 * @Author  zhnagwenkai
 * @Date 2020年5月30日 上午12:21:33
 * @Version 1.0
 */
@ResponseBody
@Controller
@RequestMapping("/courseGrade")
public class CourseGradeController extends  GenericController<CourseGrade,Long,CourseGradeManager>{

	CourseGradeManager courseGradeManager;
	
	@Autowired
	public void setCourseGradeManager(CourseGradeManager courseGradeManager) {
		this.courseGradeManager = courseGradeManager;
		this.manager = courseGradeManager;
	}
	
	@ResponseBody
	@GetMapping(value = "findall", produces = "application/json;charset=utf-8")
	public String getcourseGradeAll() {
		return JSON.toJSONString(courseGradeManager.findAll());
	}

	
	
	@GetMapping("/findbyid/{id}")
	public String fingById(@PathVariable("id") Long id) {
		Optional<CourseGrade> result = this.manager.findByCourseId(id);
		return JSON.toJSONString(result);
	}
	
	@GetMapping("/deletebyid/{id}")
	public Boolean deleteById(@PathVariable("id") Long id) {
		Boolean result = this.manager.deleteById(id);
		return result;
	}
	
	
}
